package com.melody.common.config;


import com.melody.common.interceptors.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author:
 * @Description: web拦截器
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    //拦截对象
    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(org.springframework.web.servlet.config.annotation.InterceptorRegistry registry) {
        //拦截路径
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//设置拦截器拦截的请求路径（ /** 表示拦截所有请求）
//                .excludePathPatterns("/**");//设置不拦截全部（测试用）
                .excludePathPatterns(
                        "/user/register",
                        "/user/info",
                        "/authCode",
                        "/user/codeLogin",
                        "/user/loginOrRegister",
                        "/common/upload",
                        "/music/details/rand"
                ); // 排除 /user登录和注册接口
    }
}
